package com.etc.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.entity.MusicStyle;
import com.etc.service.MusicStyleService;
import com.etc.service.impl.MusicStyleServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Servlet implementation class MusicStyleServlet
 */
@WebServlet("/MusicStyleServlet")
public class MusicStyleServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private MusicStyleService musicStyleService = new MusicStyleServiceImpl();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MusicStyleServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/plain;charset=utf-8");
		List<MusicStyle> list = musicStyleService.getMusicStyleAll();
		ObjectMapper objectMapper = new ObjectMapper();
		String json = objectMapper.writeValueAsString(list);
		PrintWriter out = response.getWriter();
		out.print(json);
	}

}
